﻿
Imports DotNetNuke
Imports DotNetNuke.Entities.Users

Imports DotNetNuke.Common
Imports DotNetNuke.Common.Utilities
Imports System.Web.UI.WebControls

Imports DotNetNuke.Entities.Modules
Imports System.Web.UI
Imports DotNetNuke.Entities.Profile
Imports Telerik.Web.UI
Imports System
Imports DotNetNuke.Framework
Imports DotNetNuke.Services.Localization
Imports System.Data
Imports System.Collections.Generic

Imports Microsoft.VisualBasic
Imports System.Text
Imports DotNetNuke.Entities.Tabs
Imports DotNetNuke.Services.FileSystem
Imports DotNetNuke.UI.WebControls
Imports DotNetNuke.Web.UI.WebControls


Namespace dnnWerk.Modules.Users
    Public Class UserModuleBase
        Inherits PortalModuleBase

#Region "Enumerations"

        Protected Enum UsernameUpdateMode
            UserSelect 'user selects the username himself
            FirstLetterLastname 'username autogenerated, username = f.lastname
            FirstnameLastname 'username autogenerated, username = firstname.lastname
            Lastname 'username autogenerated, lastname = username
            Email 'username autogenerated, email = username
        End Enum

        Protected Enum DisplaynameUpdateMode
            UserSelect 'user selects the displayname himself
            FirstLetterLastname 'autogenerated, (F.Lastname)
            FirstnameLastname 'autogenerated (Firstname Lastname)
            Lastname 'username autogenerated, (Lastname)
            Email 'autogenerated, (email address)
        End Enum


#End Region

#Region "Registration Control Settings"

        Protected ReadOnly Property AdditionalControls() As String()
            Get
                Dim strControls As String() = New String() {}

                If Not Settings("AdditionalControls") Is Nothing Then
                    Try
                        strControls = Convert.ToString(Settings("AdditionalControls")).Split(Char.Parse(";"))
                    Catch
                    End Try
                End If

                Return strControls
            End Get
        End Property

        Protected ReadOnly Property ExportFieldHeaders() As String()
            Get

                Dim strPropArray As String() = New String() {}
                Dim strProps As String = "User_UserId,User_Username,User_Firstname,User_Lastname,User_Email,User_CreatedDate,User_LastLoginDate,"

                Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
                For Each prop As ProfilePropertyDefinition In props
                    If Not String.IsNullOrEmpty(Localization.GetString(prop.PropertyName, ProfileResourcefile)) Then
                        strProps += Localization.GetString(prop.PropertyName, ProfileResourcefile) & ","
                    Else
                        strProps += prop.PropertyName & ","
                    End If
                Next

                If Not Settings("ExportFields") Is Nothing Then
                    If Not String.IsNullOrEmpty(CType(Settings("ExportFields"), String)) Then
                        strProps = ""
                        Try

                            Dim strValue As String = Convert.ToString(Settings("ExportFields"))

                            For Each sValue As String In strValue.Split(Char.Parse(","))
                                If sValue.Trim.Length > 0 Then
                                    If Not String.IsNullOrEmpty(Localization.GetString("ProfileProperties_" & sValue & ".Text", ProfileResourcefile)) Then
                                        strProps += Localization.GetString("ProfileProperties_" & sValue & ".Text", ProfileResourcefile) & ","
                                    Else
                                        strProps += sValue & ","
                                    End If
                                End If
                            Next

                        Catch
                        End Try

                    End If

                End If

                Return strProps.Split(Char.Parse(","))


            End Get
        End Property

        Protected ReadOnly Property ExportFields() As String()
            Get

                Dim strPropArray As String() = New String() {}
                Dim strProps As String = "User_UserId,User_Username,User_Firstname,User_Lastname,User_Email,User_CreatedDate,User_LastLoginDate,"

                Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
                For Each prop As ProfilePropertyDefinition In props
                    strProps += prop.PropertyName & ","
                Next

                If Not Settings("ExportFields") Is Nothing Then
                    Try
                        Dim strValue As String = Convert.ToString(Settings("ExportFields"))
                        If strValue.Trim.Length > 0 Then
                            strPropArray = strValue.Split(Char.Parse(","))
                        End If
                    Catch
                    End Try
                End If

                If strPropArray.Length > 0 Then
                    Return strPropArray
                End If

                Return strProps.Split(Char.Parse(","))

            End Get
        End Property

        Protected ReadOnly Property ShowUserDetailTabs() As String()
            Get
                Dim strControls As String() = New String() {"Account", "Password", "Profile", "Roles", "Email"}

                If Not Settings("ShowUserDetailTabs") Is Nothing Then
                    Try
                        Dim strValue As String = Convert.ToString(Settings("ShowUserDetailTabs"))
                        If strValue.Length > 0 Then
                            strControls = strValue.Split(Char.Parse(","))
                        End If
                    Catch
                    End Try
                End If

                Return strControls
            End Get
        End Property

        Protected ReadOnly Property CanRunReports() As Boolean
            Get
                If Not Settings("CanRunReports") Is Nothing Then
                    Return CType(Settings("CanRunReports"), Boolean)
                End If
                Return True
            End Get
        End Property

        Protected ReadOnly Property BrowseRoles() As String()
            Get
                If Not Settings("BrowseRoles") Is Nothing Then
                    Return CType(Settings("BrowseRoles"), String).Split(Char.Parse(";"))
                End If
                Return Nothing
            End Get
        End Property

        Protected ReadOnly Property PreSelectRole() As Integer
            Get
                If Not Settings("PreSelectRole") Is Nothing Then
                    Return CType(Settings("PreSelectRole"), Integer)
                End If
                Return Null.NullInteger
            End Get
        End Property

        Protected ReadOnly Property AllowExport() As Boolean
            Get
                If Not Settings("AllowExport") Is Nothing Then
                    Return CType(Settings("AllowExport"), Boolean)
                End If
                Return True
            End Get
        End Property

        Protected ReadOnly Property AllowCreate() As Boolean
            Get
                If Not Settings("AllowCreate") Is Nothing Then
                    Return CType(Settings("AllowCreate"), Boolean)
                End If
                Return False
            End Get
        End Property

        Protected ReadOnly Property AllowHardDelete() As Boolean
            Get
                If Not Settings("AllowHardDelete") Is Nothing Then
                    Return CType(Settings("AllowHardDelete"), Boolean)
                End If
                Return False
            End Get
        End Property

        Protected ReadOnly Property AllowDelete() As Boolean
            Get
                If Not Settings("AllowDelete") Is Nothing Then
                    Return CType(Settings("AllowDelete"), Boolean)
                End If
                Return False
            End Get
        End Property

        Protected ReadOnly Property UsernameMode() As UsernameUpdateMode
            Get
                If Not Settings("ShowUserName") Is Nothing Then
                    Select Case CType(Settings("ShowUserName"), String)
                        Case "EMAIL"
                            Return UsernameUpdateMode.Email
                        Case "FIRSTLETTER.LASTNAME"
                            Return UsernameUpdateMode.FirstLetterLastname
                        Case "FIRSTNAME.LASTNAME"
                            Return UsernameUpdateMode.FirstnameLastname
                        Case "LASTNAME"
                            Return UsernameUpdateMode.Lastname
                        Case Else
                            Return UsernameUpdateMode.UserSelect
                    End Select
                End If
                Return UsernameUpdateMode.UserSelect
            End Get
        End Property

        Protected ReadOnly Property DisplaynameMode() As DisplaynameUpdateMode
            Get
                If Not Settings("ShowDisplayName") Is Nothing Then
                    Select Case CType(Settings("ShowDisplayName"), String)
                        Case "EMAIL"
                            Return DisplaynameUpdateMode.Email
                        Case "FIRSTLETTER.LASTNAME"
                            Return DisplaynameUpdateMode.FirstLetterLastname
                        Case "FIRSTNAME.LASTNAME"
                            Return DisplaynameUpdateMode.FirstnameLastname
                        Case "LASTNAME"
                            Return DisplaynameUpdateMode.Lastname
                        Case Else
                            Return DisplaynameUpdateMode.UserSelect
                    End Select
                End If
                Return DisplaynameUpdateMode.UserSelect
            End Get
        End Property

        Protected ReadOnly Property RedirectAfterVerify() As String
            Get
                If Not Settings("RedirectAfterVerify") Is Nothing Then
                    If IsNumeric(CType(Settings("RedirectAfterVerify"), String)) Then
                        'must be a tab
                        Dim tc As New TabController
                        Dim t As DotNetNuke.Entities.Tabs.TabInfo = tc.GetTab(CType(Settings("RedirectAfterVerify"), Integer), PortalId, False)
                        If Not t Is Nothing Then
                            Return t.FullUrl
                        End If
                    Else
                        Return CType(Settings("RedirectAfterVerify"), String)
                    End If
                End If
                Return Null.NullString
            End Get
        End Property

        Protected ReadOnly Property RedirectAfterSubmit() As String
            Get
                If Not Settings("RedirectAfterSubmit") Is Nothing Then
                    If IsNumeric(CType(Settings("RedirectAfterSubmit"), String)) Then
                        'must be a tab
                        Dim tc As New TabController
                        Dim t As DotNetNuke.Entities.Tabs.TabInfo = tc.GetTab(CType(Settings("RedirectAfterSubmit"), Integer), PortalId, False)
                        If Not t Is Nothing Then
                            Return t.FullUrl
                        End If
                    Else
                        Return CType(Settings("RedirectAfterSubmit"), String)
                    End If
                End If
                Return Null.NullString
            End Get
        End Property

        Protected ReadOnly Property NotifyAddress() As String
            Get
                If Not Settings("NotifyAddress") Is Nothing Then
                    Return CType(Settings("NotifyAddress"), String)
                End If
                Return Null.NullString
            End Get
        End Property

        Protected ReadOnly Property NotifyUser() As Boolean
            Get
                If Not Settings("NotifyUser") Is Nothing Then
                    Return CType(Settings("NotifyUser"), Boolean)
                End If
                Return False
            End Get
        End Property

        Protected ReadOnly Property IncludeHeaders() As Boolean
            Get
                If Not Settings("IncludeHeaders") Is Nothing Then
                    Return CType(Settings("IncludeHeaders"), Boolean)
                End If
                Return True
            End Get
        End Property

        Protected ReadOnly Property AddToRoleOnSubmit() As Integer
            Get
                If Not Settings("AddToRoleOnSubmit") Is Nothing Then
                    Try
                        Return CType(Settings("AddToRoleOnSubmit"), Integer)
                    Catch ex As Exception
                    End Try
                End If
                Return Null.NullInteger
            End Get
        End Property

        Protected ReadOnly Property RemoveFromRoleOnSubmit() As Integer
            Get
                If Not Settings("RemoveFromRoleOnSubmit") Is Nothing Then
                    Try
                        Return CType(Settings("RemoveFromRoleOnSubmit"), Integer)
                    Catch ex As Exception
                    End Try
                End If
                Return Null.NullInteger
            End Get
        End Property

        Protected ReadOnly Property FilterByRole() As String
            Get
                If Not Settings("FilterByRole") Is Nothing Then
                    Return CType(Settings("FilterByRole"), String)
                End If
                Return Null.NullString
            End Get
        End Property

        Protected ReadOnly Property PreloadList() As Boolean
            Get
                If Not Settings("PreloadList") Is Nothing Then
                    Return CType(Settings("PreloadList"), Boolean)
                End If
                Return False
            End Get
        End Property

        Protected ReadOnly Property FilterSelectByRole() As Integer
            Get
                If Not Settings("FilterSelectByRole") Is Nothing Then
                    Return CType(Settings("FilterSelectByRole"), Integer)
                End If
                Return Null.NullInteger
            End Get
        End Property

        Public ReadOnly Property ControlToLoad() As String
            Get
                If CType(Settings("ControlToLoad"), String) <> "" Then
                    Return CType(Settings("ControlToLoad"), String)
                End If
                Return ""
            End Get
        End Property

        Public ReadOnly Property UsermanagementTab() As Integer
            Get
                If CType(Settings("UsermanagementTab"), String) <> "" Then
                    Return CType(Settings("UsermanagementTab"), Integer)
                End If
                Return PortalSettings.HomeTabId
            End Get
        End Property

        Public ReadOnly Property UserManagementTemplates() As List(Of String)
            Get
                Dim lst As New List(Of String)
                lst.Add("Email.Account.Created")
                lst.Add("Email.Account.Data")
                lst.Add("Email.AddedToRole")
                lst.Add("Email.Password.Reset")
                lst.Add("User.Create")
                lst.Add("User.Edit")
                lst.Add("User.Profile")
                Return lst
            End Get
        End Property

        Public ReadOnly Property UserProfileTemplates() As List(Of String)
            Get
                Dim lst As New List(Of String)
                lst.Add("User.Profile")
                lst.Add("Email.Updated.User")
                lst.Add("Email.Updated.Admin")
                Return lst
            End Get
        End Property

        Public ReadOnly Property UserRegistrationTemplates() As List(Of String)
            Get
                Dim lst As New List(Of String)
                lst.Add("User.Register")
                lst.Add("Email.Admin.Created")
                lst.Add("Email.User.Created.Private")
                lst.Add("Email.User.Created.Verified")
                lst.Add("Email.User.Created")
                Return lst
            End Get
        End Property

        Public ReadOnly Property MemberlistTemplates() As List(Of String)
            Get
                Dim lst As New List(Of String)
                lst.Add("Member.List.Header")
                lst.Add("Member.List.Item")
                lst.Add("Member.List.AlternatingItem")
                lst.Add("Member.List.Footer")
                lst.Add("Member.List.Detail")
                Return lst
            End Get
        End Property

        Public ReadOnly Property ModuleOperationModes() As List(Of String)
            Get
                Dim lst As New List(Of String)
                lst.Add("ManageUsers")
                lst.Add("UserProfile")
                lst.Add("UserRegister")
                lst.Add("Memberlist")
                Return lst
            End Get
        End Property

        Public ReadOnly Property Template_EmailPasswordReset(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Password.Reset." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Password.Reset." & strLocale & ".txt"))
                        End If
                    End If
                End If

                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Password.Reset.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_EmailAccountCreated(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Account.Created." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/Email.Account.Created." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Account.Created.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_RegisterAccount_Admin(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.Admin.Created." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.Admin.Created." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.Admin.Created.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_RegisterAccount_UserPrivate(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Private." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Private." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Private.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_RegisterAccount_UserVerified(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Verified." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Verified." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.Verified.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_RegisterAccount_User(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/Email.User.Created.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_ProfileUpdate_Admin(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.Admin." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.Admin." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.Admin.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_Email_ProfileUpdate_User(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.User." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.User." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/Email.Updated.User.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_EmailAccountData(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Account.Data." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Account.Data." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.Account.Data.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_EmailAddedToRole(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.AddedToRole." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.AddedToRole." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.AddedToRole.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_EmailRemovedFromRole(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.RemovedFromRole." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.RemovedFromRole." & strLocale & ".txt"))
                        End If
                    End If
                End If
                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/Email.RemovedFromRole.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_CreateAccount(ByVal strLocale As String) As String
            Get

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then
                        If System.IO.File.Exists(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Create." & strLocale & ".txt")) Then
                            Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Create." & strLocale & ".txt"))
                        End If
                    End If
                End If

                Return TemplateController.GetTemplate(Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Create.txt"))

            End Get
        End Property

        Public ReadOnly Property Template_EditAccount(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Edit.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Edit." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Edit.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_EditAccount()


            End Get
        End Property

        Public ReadOnly Property Template_EditProfile(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Profile.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Profile." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/ManageUsers/" & ModuleId.ToString & "/User.Profile.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_EditProfile()

            End Get
        End Property


        Public ReadOnly Property Template_UserRegistration(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/User.Register.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/User.Register." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserRegister/" & ModuleId.ToString & "/User.Register.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserRegistration()


            End Get
        End Property

        Public ReadOnly Property Template_UserProfile(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/User.Profile.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/User.Profile." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/UserProfile/" & ModuleId.ToString & "/User.Profile.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserProfile()


            End Get
        End Property

        Public ReadOnly Property Template_UserListHeader(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Header.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Header." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Header.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserListHeader()


            End Get
        End Property

        Public ReadOnly Property Template_UserListItem(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Item.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Item." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Item.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserListItem()


            End Get
        End Property

        Public ReadOnly Property Template_UserListAlternatingItem(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.AlternatingItem.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.AlternatingItem." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.AlternatingItem.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserListItem()


            End Get
        End Property

        Public ReadOnly Property Template_UserListFooter(ByVal strLocale As String) As String
            Get

                Dim path As String = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Footer.txt")

                If Not strLocale Is Nothing Then
                    If strLocale <> "" Then

                        path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Footer." & strLocale & ".txt")

                        If System.IO.File.Exists(path) Then
                            Return TemplateController.GetTemplate(path)
                        End If

                    End If
                End If

                path = Server.MapPath(Me.TemplateSourceDirectory & "/Templates/Memberlist/" & ModuleId.ToString & "/User.List.Footer.txt")

                If System.IO.File.Exists(path) Then
                    Return TemplateController.GetTemplate(path)
                End If

                Return DefaultTemplate_UserListFooter()


            End Get
        End Property

#End Region

#Region "Common Properties"

        Public ReadOnly Property CurrentLocale() As String
            Get
                Return CType(Page, PageBase).PageCulture.Name
            End Get
        End Property

        Public ReadOnly Property ModuleDirectory() As String
            Get
                Return "~/Desktopmodules/Admin/dnnWerk.Users"
            End Get
        End Property

        Protected ReadOnly Property ProfileResourcefile() As String
            Get
                Return ResolveUrl("~/Desktopmodules/Admin/Security/App_LocalResources/Profile.ascx")
            End Get
        End Property

        Protected ReadOnly Property SharedResourcefile() As String
            Get
                Return ResolveUrl("~/Desktopmodules/Admin/dnnWerk.Users/App_LocalResources/UserModule.ascx")
            End Get
        End Property

        Protected ReadOnly Property User() As Entities.Users.UserInfo
            Get
                Dim oUser As UserInfo = Nothing
                If Not Request.QueryString("uid") Is Nothing Then
                    If Microsoft.VisualBasic.IsNumeric(Request.QueryString("uid")) Then
                        oUser = UserController.GetUserById(PortalId, Convert.ToInt32(Request.QueryString("uid")))
                    End If
                Else
                    oUser = UserController.GetCurrentUserInfo
                End If
                Return oUser
            End Get
        End Property

        Public ReadOnly Property IsUser() As Boolean
            Get
                If Not User Is Nothing Then
                    If User.UserID = UserInfo.UserID Then
                        Return True
                    End If
                End If
                Return False
            End Get
        End Property

        Public ReadOnly Property IsAdmin() As Boolean
            Get
                Return UserInfo.IsInRole(PortalSettings.AdministratorRoleName)
            End Get
        End Property

#End Region

#Region "Shared Helper Methods"

        Protected Function IsValidUserAttribute(ByVal Attribute As String, ByVal objRoot As Control) As Boolean

            Dim id As String = ""
            Select Case Attribute
                Case Constants.User_Username
                    id = Constants.ControlId_Username
                Case Constants.User_Displayname
                    id = Constants.ControlId_Displayname
                Case Constants.User_Firstname
                    id = Constants.ControlId_Firstname
                Case Constants.User_Lastname
                    id = Constants.ControlId_Lastname
                Case Constants.User_Password1
                    id = Constants.ControlId_Password1
                Case Constants.User_Password2
                    id = Constants.ControlId_Password2
                Case Constants.User_Email
                    id = Constants.ControlId_Email
            End Select

            Dim txtbox As TextBox = CType(FindControlRecursive(objRoot, objRoot.ID & "_" & id), TextBox)
            If Not txtbox Is Nothing Then
                If txtbox.Text <> "" Then
                    If id = Constants.ControlId_Email Then
                        Return IsValidEmail(txtbox.Text)
                    Else
                        Return True
                    End If
                End If
            End If
            Return False

        End Function

        'todo: implement portalsettings validation
        Protected Function IsValidEmail(ByVal strEmail As String) As Boolean
            Return Regex.IsMatch(strEmail, "^[a-zA-Z0-9_%+#&'*/=^`{|}~-](?:\.?[a-zA-Z0-9_%+#&'*/=^`{|}~-])*@(?:[a-zA-Z0-9_](?:(?:\.?|-*)[a-zA-Z0-9_])*\.[a-zA-Z]{2,9}|\[(?:2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?:2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?:2[0-4]\d|25[0-5]|[01]?\d\d?)\.(?:2[0-4]\d|25[0-5]|[01]?\d\d?)])$")
        End Function

        Protected Function IsValidProperty(ByVal objUser As UserInfo, ByVal ProfProperty As ProfilePropertyDefinition, ByRef objControl As Control) As Boolean

            If ProfProperty.Required = False Then
                Return True
            End If

            Dim ctl As Control = GetPropertyControl(ProfProperty, objControl)
            If Not ctl Is Nothing Then

                If TypeOf (ctl) Is Telerik.Web.UI.RadComboBox Then
                    If CType(ctl, Telerik.Web.UI.RadComboBox).Text <> "" Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is TextBox Then
                    If CType(ctl, TextBox).Text <> "" Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadDateTimePicker Then
                    If Not CType(ctl, Telerik.Web.UI.RadDateTimePicker).DbSelectedDate Is Nothing Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadDatePicker Then
                    If Not CType(ctl, Telerik.Web.UI.RadDatePicker).DbSelectedDate Is Nothing Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadNumericTextBox Then
                    If CType(ctl, RadNumericTextBox).Value >= 0 Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is DotNetNuke.Web.UI.WebControls.DnnImageEditControl Then
                    If CType(ctl, DotNetNuke.Web.UI.WebControls.DnnImageEditControl).Value <> "" Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is DotNetNuke.Web.UI.WebControls.DnnFileEditControl Then
                    If CType(ctl, DotNetNuke.Web.UI.WebControls.DnnFileEditControl).Value <> "" Then
                        Return True
                    Else
                        Return False
                    End If
                ElseIf TypeOf (ctl) Is CheckBox Then
                    If Not CType(ctl, CheckBox).Checked = False Then
                        Return True
                    Else
                        Return False
                    End If
                End If

            End If

            Return True

        End Function

        Protected Function GetPropertyType(ByVal TypeId As Integer) As String
            Dim lc As New DotNetNuke.Common.Lists.ListController
            Dim entry As Lists.ListEntryInfo = lc.GetListEntryInfo(TypeId)
            If Not entry Is Nothing Then
                Return entry.Value
            End If
            Return ""
        End Function

        Public Function FindControlRecursive(ByVal objRoot As Control, ByVal id As String) As Control
            If objRoot.ID = id Then
                Return objRoot
            End If
            For Each c As Control In objRoot.Controls
                Dim t As Control = FindControlRecursive(c, id)
                If Not t Is Nothing Then
                    Return t
                End If
            Next
            Return Nothing
        End Function

        Protected Function IsRegisterMode() As Boolean
            Return (Request.IsAuthenticated = False)
        End Function

        'todo: implement forms pattern
        Protected Function DefaultTemplate_UserRegistration() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Username")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Username")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Username")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Username")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Displayname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Displayname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Displayname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Displayname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Firstname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Firstname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Firstname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Firstname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Lastname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Lastname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Lastname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Lastname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Email")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Email")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Email")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Email")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password1")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password1")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password1")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password1")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password2")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password2")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password2")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password2")
            sb.Append(strItem & vbCrLf & vbCrLf)

            Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
            For Each prop As ProfilePropertyDefinition In props

                If Not prop.Deleted Then
                    strItem = Constants.DefaultItemTemplate

                    strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:PROFILEHELP:" & prop.PropertyName)
                    strItem = strItem.Replace("RESX:PROPERTY", "RESX:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("CTL:PROPERTY", "CTL:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:PROFILE:" & prop.PropertyName)
                    sb.Append(strItem & vbCrLf & vbCrLf)
                End If

            Next

            sb.Append("<div class=""dnnClear"">" & vbCrLf)
            sb.Append("  <div class=""Right"">[CTL:UPDATEBUTTON:Create Account]</div>" & vbCrLf)
            sb.Append("</div>" & vbCrLf)


            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_UserListHeader() As String

            Return "<div class=""dnnwerk_userlist"">"

        End Function

        Protected Function DefaultTemplate_UserListItem() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            sb.Append("<div class=""dnnwerk_useritem"">" & vbCrLf)
            sb.Append("  <h2>[DISPLAYNAME]</h2>" & vbCrLf)
            sb.Append("  <p>[PROFILE:CITY],[PROFILE:COUNTRY]</p>" & vbCrLf)
            sb.Append("  <p class=""dnnwerk_itemlink""><a href=""dnnwerk_userdetail_[USERID]"">Details</a></p>" & vbCrLf)
            sb.Append("  <div id=""dnnwerk_userdetail_[USERID]"">" & vbCrLf)
            sb.Append("     <p>Hello, I am a user detail dialog</p>" & vbCrLf)
            sb.Append("  </div class=""dnnwerk_userdetail"">" & vbCrLf)
            sb.Append("</div>" & vbCrLf & vbCrLf)

            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_UserListDetail() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            sb.Append("<div class=""dnnwerk_userdetail"">" & vbCrLf)
            sb.Append("  <h2>[DISPLAYNAME]</h2>" & vbCrLf)
            sb.Append("  <p>[PROFILE:CITY],[PROFILE:COUNTRY]</p>" & vbCrLf)
            sb.Append("  <p>Hello, I am a user detail dialog</p>" & vbCrLf)
            sb.Append("</div>" & vbCrLf & vbCrLf)

            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_UserListFooter() As String

            Return "</div>"

        End Function

        Protected Function DefaultTemplate_UserProfile() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Username")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Username")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Username")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Username")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Displayname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Displayname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Displayname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Displayname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Firstname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Firstname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Firstname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Firstname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Lastname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Lastname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Lastname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Lastname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Email")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Email")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Email")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Email")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password1")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password1")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password1")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password1")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password2")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password2")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password2")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password2")
            sb.Append(strItem & vbCrLf & vbCrLf)

            Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
            For Each prop As ProfilePropertyDefinition In props

                If Not prop.Deleted Then

                    strItem = Constants.DefaultItemTemplate

                    strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:PROFILEHELP:" & prop.PropertyName)
                    strItem = strItem.Replace("RESX:PROPERTY", "RESX:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("CTL:PROPERTY", "CTL:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:PROFILE:" & prop.PropertyName)
                    sb.Append(strItem & vbCrLf & vbCrLf)

                End If

            Next

            sb.Append("<div class=""dnnClear"">" & vbCrLf)
            sb.Append("  <div class=""Right"">[CTL:DELETEBUTTON:Close Account]</div>" & vbCrLf)
            sb.Append("  <div class=""Right"">[CTL:UPDATEBUTTON:Update Account]</div>" & vbCrLf)
            sb.Append("</div>" & vbCrLf)


            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_EditProfile() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Username")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Username")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Username")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Username")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Displayname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Displayname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Displayname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Displayname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Firstname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Firstname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Firstname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Firstname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Lastname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Lastname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Lastname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Lastname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Email")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Email")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Email")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Email")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password1")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password1")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password1")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password1")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:USERHELP:Password2")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password2")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password2")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password2")
            sb.Append(strItem & vbCrLf & vbCrLf)

            Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
            For Each prop As ProfilePropertyDefinition In props
                If Not prop.Deleted Then

                    strItem = Constants.DefaultItemTemplate

                    strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:PROFILEHELP:" & prop.PropertyName)
                    strItem = strItem.Replace("RESX:PROPERTY", "RESX:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("CTL:PROPERTY", "CTL:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:PROFILE:" & prop.PropertyName)
                    sb.Append(strItem & vbCrLf & vbCrLf)

                End If
            Next

            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_ManageProfile() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            Dim props As ProfilePropertyDefinitionCollection = ProfileController.GetPropertyDefinitionsByPortal(PortalSettings.PortalId)
            For Each prop As ProfilePropertyDefinition In props

                If Not prop.Deleted Then

                    strItem = Constants.DefaultItemTemplate

                    strItem = strItem.Replace("RESX:PROPERTYHELP", "RESX:PROFILEHELP:" & prop.PropertyName)
                    strItem = strItem.Replace("RESX:PROPERTY", "RESX:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("CTL:PROPERTY", "CTL:PROFILE:" & prop.PropertyName)
                    strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:PROFILE:" & prop.PropertyName)
                    sb.Append(strItem & vbCrLf & vbCrLf)

                End If

            Next


            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_EditAccount() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Username")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Username")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Username")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Username")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Displayname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Displayname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Displayname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Displayname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Email")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Email")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Email")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Email")
            sb.Append(strItem & vbCrLf & vbCrLf)

            Return sb.ToString

        End Function

        Protected Function DefaultTemplate_CreateAccount() As String

            Dim strItem As String = ""
            Dim sb As New StringBuilder

            strItem = Constants.DefaultItemTemplate
            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Username")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Username")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Username")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Username")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Displayname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Displayname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Displayname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Displayname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Firstname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Firstname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Firstname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Firstname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Lastname")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Lastname")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Lastname")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Lastname")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Email")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Email")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Email")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Email")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Password1")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password1")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password1")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password1")
            sb.Append(strItem & vbCrLf & vbCrLf)

            strItem = Constants.DefaultItemTemplate

            strItem = strItem.Replace("RESX:PROPERTYHELP:PROPERTY", "RESX:USERHELP:Password2")
            strItem = strItem.Replace("RESX:PROPERTY", "RESX:USER:Password2")
            strItem = strItem.Replace("CTL:PROPERTY", "CTL:USER:Password2")
            strItem = strItem.Replace("REQUIRED:PROPERTY", "REQUIRED:USER:Password2")
            sb.Append(strItem & vbCrLf & vbCrLf)

            Return sb.ToString

        End Function

#End Region

#Region "Shared DataAccess Helpers"

        Protected Function GetPropertyValueList(ByVal PropertyDefinition As ProfilePropertyDefinition) As List(Of String)

            Dim lst As List(Of String) = Nothing

            If Not DataCache.GetCache("dnnwerk_ValueList_" & PropertyDefinition.PropertyDefinitionId.ToString) Is Nothing Then
                lst = CType(DataCache.GetCache("dnnwerk_ValueList_" & PropertyDefinition.PropertyDefinitionId.ToString), List(Of String))
            End If

            If lst Is Nothing Then

                lst = New List(Of String)

                Dim dr As IDataReader = Nothing
                If FilterSelectByRole = Null.NullInteger Then
                    dr = DotNetNuke.Data.DataProvider.Instance().ExecuteReader("dnnWerk_Users_GetValueList", PropertyDefinition.PropertyDefinitionId, DBNull.Value)
                Else
                    dr = DotNetNuke.Data.DataProvider.Instance().ExecuteReader("dnnWerk_Users_GetValueList", PropertyDefinition.PropertyDefinitionId, FilterSelectByRole)
                End If


                If Not dr Is Nothing Then
                    While dr.Read

                        Dim strValueSimpliefied As String = Convert.ToString(dr("PropertyValue"))

                        If strValueSimpliefied.Contains(",") Then

                            Dim strValue As String() = strValueSimpliefied.Split(Char.Parse(","))
                            For Each strItem As String In strValue

                                If strItem.Trim.Length > 0 Then
                                    If Not lst.Contains(strItem) Then
                                        lst.Add(strItem)
                                    End If
                                End If
                            Next

                        Else

                            If Not lst.Contains(strValueSimpliefied) Then
                                If strValueSimpliefied.Trim.Length > 0 Then
                                    lst.Add(strValueSimpliefied)
                                End If
                            End If

                        End If


                    End While

                    dr.Close()
                    dr.Dispose()

                    'DataCache.SetCache("dnnwerk_ValueList_" & PropertyDefinition.PropertyDefinitionId.ToString, lst)

                End If


            End If

            Return lst

        End Function

        Protected Function GetUsers() As DataSet

            Dim ds As DataSet = Nothing
            Dim dr As IDataReader = Nothing

            If Not DataCache.GetCache("dnnwerk_Userlist") Is Nothing Then
                ds = CType(DataCache.GetCache("dnnwerk_Userlist"), DataSet)
            End If

            If ds Is Nothing Then

                If FilterByRole = Null.NullString Then
                    dr = DotNetNuke.Data.DataProvider.Instance().ExecuteReader("dnnWerk_Users_ListByPortal", PortalId)
                Else
                    dr = DotNetNuke.Data.DataProvider.Instance().ExecuteReader("dnnWerk_Users_ListByRole", PortalId, FilterByRole)
                End If

                Dim dt As New DataTable
                dt.Load(dr)
                ds.Tables.Add(dt)

                DataCache.SetCache("dnnwerk_Userlist", ds)

            End If

            Return ds

        End Function

#End Region

#Region "Shared Template Processing Methods"

        Protected Sub ProcessDisplayTemplate(ByRef plhControls As ControlCollection, ByVal objItem As UserInfo, ByVal Template As String)

            Dim literal As New Literal
            Dim delimStr As String = "[]"
            Dim delimiter As Char() = delimStr.ToCharArray()

            Dim templateArray As String()
            templateArray = Template.Split(delimiter)

            For iPtr As Integer = 0 To templateArray.Length - 1 Step 2

                Dim strHTML As String = templateArray(iPtr).ToString()
                plhControls.Add(New LiteralControl(strHTML))

                If iPtr < templateArray.Length - 1 Then

                    Dim strToken As String = templateArray(iPtr + 1)

                    Select Case strToken

                        Case "USERID"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.UserID.ToString
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try

                        Case "USERNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.Username.ToString
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "CREATEDDATE"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.CreatedOnDate.ToLongDateString
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "CREATEDDATELONG"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.CreatedOnDate.ToLongDateString
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try

                        Case "FIRSTNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.FirstName
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "LASTNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.LastName
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "EMAIL"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.Email
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "DISPLAYNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem.DisplayName
                                objLiteral.EnableViewState = False
                                plhControls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case Else

                            If (strToken.StartsWith("PROFILE:")) Then

                                Dim strProperty As String = strToken.Substring(8, strToken.Length - 8)

                                Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                                If Not prop Is Nothing Then

                                    AddPropertyValue(plhControls, prop, objItem)

                                End If

                            End If

                    End Select

                End If

            Next

        End Sub

        Protected Sub ProcessDisplayTemplate(ByRef plhControls As PlaceHolder, ByVal objItem As DataRowView, ByVal Template As String)

            Dim literal As New Literal
            Dim delimStr As String = "[]"
            Dim delimiter As Char() = delimStr.ToCharArray()

            Dim templateArray As String()
            templateArray = Template.Split(delimiter)

            For iPtr As Integer = 0 To templateArray.Length - 1 Step 2

                Dim strHTML As String = templateArray(iPtr).ToString()
                plhControls.Controls.Add(New LiteralControl(strHTML))

                If iPtr < templateArray.Length - 1 Then

                    Dim strToken As String = templateArray(iPtr + 1)

                    Select Case strToken

                        Case "USERID"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("UserId")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try

                        Case "USERNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("Username")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "CREATEDDATE"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = Convert.ToDateTime(objItem("CreatedDate")).ToLongDateString
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "CREATEDDATELONG"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = Convert.ToDateTime(objItem("CreatedDate")).ToLongDateString
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try

                        Case "FIRSTNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("FirstName")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "LASTNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("LastName")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "EMAIL"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("Email")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case "DISPLAYNAME"

                            Try
                                Dim objLiteral As New Literal
                                objLiteral.Text = objItem("DisplayName")
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            Catch ex As Exception

                            End Try


                        Case Else

                            If (strToken.StartsWith("PROFILE:")) Then

                                Dim strProperty As String = strToken.Substring(8, strToken.Length - 8)

                                Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                                If Not prop Is Nothing Then

                                    AddPropertyValue(plhControls, prop, objItem)

                                End If

                            End If

                    End Select

                End If

            Next

        End Sub

        Protected Sub ProcessFormTemplate(ByRef plhControls As PlaceHolder, ByVal Template As String, ByVal objUser As UserInfo, ByRef PageNeedsToPostback As Boolean)

            plhControls.Controls.Clear()
            Dim strIdent As String = plhControls.ID & "_"

            Dim literal As New Literal
            Dim delimStr As String = "[]"
            Dim delimiter As Char() = delimStr.ToCharArray()

            Dim templateArray As String()
            templateArray = Template.Split(delimiter)

            For iPtr As Integer = 0 To templateArray.Length - 1 Step 2

                Dim strHTML As String = templateArray(iPtr).ToString()
                plhControls.Controls.Add(New LiteralControl(strHTML))

                If iPtr < templateArray.Length - 1 Then

                    Dim strToken As String = templateArray(iPtr + 1)

                    If strToken.StartsWith("RESX:") Then

                        Dim strKey As String = strToken.Split(Char.Parse(":"))(2)
                        Dim strTarget As String = strToken.Split(Char.Parse(":"))(1)

                        Dim blnHideRequiredIndicator As Boolean = False
                        Try
                            blnHideRequiredIndicator = (Not String.IsNullOrEmpty(strToken.Split(Char.Parse(":"))(3)) AndAlso (strToken.Split(Char.Parse(":"))(3).ToLower = "hiderequired"))
                        Catch
                        End Try

                        Dim strValue As String = Localization.GetString(strKey, SharedResourcefile)
                        Dim strTargetControlId As String = ""
                        Dim prop As ProfilePropertyDefinition = Nothing
                        Dim strType As String = ""

                        If strTarget = "PROFILE" Then
                            prop = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strKey)
                            strType = GetPropertyType(prop.DataType)
                        End If


                        If strTarget.ToUpper = "USER" Then
                            strValue = Localization.GetString(strKey, SharedResourcefile)
                            Select Case strKey.ToLower
                                Case "username"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Username
                                Case "email"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Email
                                Case "displayname"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Displayname
                                Case "firstname"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Firstname
                                Case "lastname"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Lastname
                                Case "password1"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Password1
                                Case "password2"
                                    strTargetControlId = plhControls.ID & "_" & Constants.ControlId_Password2
                            End Select
                        End If

                        If strTarget.ToUpper = "USERHELP" Then
                            strValue = Localization.GetString(strKey & ".Help", SharedResourcefile)
                        End If

                        If strTarget.ToUpper = "PROFILE" Then
                            strValue = Localization.GetString("ProfileProperties_" & strKey, ProfileResourcefile)
                            strTargetControlId = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & prop.PropertyDefinitionId.ToString

                        End If

                        If strTarget.ToUpper = "PROFILEHELP" Then
                            strValue = Localization.GetString("ProfileProperties_" & strKey & ".Help", ProfileResourcefile)
                        End If

                        If strValue = "" Then
                            strValue = strKey
                        End If

                        If strValue <> "" Then

                            If strTargetControlId <> "" AndAlso blnHideRequiredIndicator = False Then

                                If strType.ToLower = "region" Then
                                    'special case region: two labels needed, one for dropdown, one for textbox

                                    Dim objLabelDrop As New Label
                                    objLabelDrop.Text = strValue
                                    objLabelDrop.AssociatedControlID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_DropdownSuffix & prop.PropertyDefinitionId.ToString
                                    objLabelDrop.ID = plhControls.ID & "_RESX_" & strTarget & Constants.ControlId_DropdownSuffix & "_" & strKey

                                    If strTarget.ToUpper = "PROFILE" Then
                                        If prop.Required Then
                                            objLabelDrop.CssClass = "dnnFormRequired"
                                        End If
                                    End If
                                    plhControls.Controls.Add(objLabelDrop)

                                    Dim objLabelText As New Label
                                    objLabelText.Text = strValue
                                    objLabelText.AssociatedControlID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_TextSuffix & prop.PropertyDefinitionId.ToString
                                    objLabelText.ID = plhControls.ID & "_RESX_" & strTarget & Constants.ControlId_TextSuffix & "_" & strKey

                                    If strTarget.ToUpper = "PROFILE" Then
                                        If prop.Required Then
                                            objLabelDrop.CssClass = "dnnFormRequired"
                                        End If
                                    End If
                                    plhControls.Controls.Add(objLabelText)

                                Else

                                    Dim objLabel As New Label
                                    objLabel.Text = strValue
                                    objLabel.AssociatedControlID = strTargetControlId
                                    objLabel.ID = plhControls.ID & "_RESX_" & strTarget & "_" & strKey

                                    If strTarget.ToUpper = "USER" Then
                                        objLabel.CssClass = "dnnFormRequired"
                                    End If
                                    If strTarget.ToUpper = "PROFILE" Then
                                        If prop.Required Then
                                            objLabel.CssClass = "dnnFormRequired"
                                        End If
                                    End If
                                    plhControls.Controls.Add(objLabel)

                                End If
                            Else
                                Dim objLiteral As New Literal
                                objLiteral.Text = strValue
                                objLiteral.ID = plhControls.ID & "_RESX_" & strTarget & "_" & strKey
                                objLiteral.EnableViewState = False
                                plhControls.Controls.Add(objLiteral)
                            End If

                        End If

                    ElseIf strToken.StartsWith("LBL:") Then

                        If Not objUser Is Nothing Then

                            Dim strControlToken As String = strToken.Substring(4, strToken.Length - 4)
                            Dim strType As String = strControlToken.Substring(0, strControlToken.IndexOf(":"))
                            Dim strProperty As String = strControlToken.Substring(strControlToken.IndexOf(":") + 1)
                            Dim strvalue As String = ""

                            If strType.ToUpper = "PROFILE" Then

                                Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                                If Not prop Is Nothing Then
                                    Try
                                        strvalue = objUser.Profile.GetPropertyValue(prop.PropertyName)
                                    Catch
                                    End Try
                                End If

                            ElseIf strType.ToUpper = "USER" Then

                                Select Case strProperty.ToUpper
                                    Case "USERNAME"
                                        strvalue = objUser.Username
                                    Case "FIRSTNAME"
                                        strvalue = objUser.FirstName
                                    Case "LASTNAME"
                                        strvalue = objUser.LastName
                                    Case "EMAIL"
                                        strvalue = objUser.Email
                                    Case "DISPLAYNAME"
                                        strvalue = objUser.DisplayName
                                    Case "MEMBERSINCE"
                                        strvalue = objUser.CreatedOnDate.ToShortDateString
                                End Select

                            End If

                            Dim ctl As New Label
                            ctl.CssClass = "UserobjectLabel"
                            ctl.EnableViewState = False
                            ctl.Text = strvalue
                            plhControls.Controls.Add(ctl)


                        End If

                    ElseIf strToken.StartsWith("CTL:") Then

                        Dim strControlToken As String = ""
                        Try
                            strControlToken = strToken.Substring(4, strToken.Length - 4)
                        Catch
                        End Try

                        Dim strType As String = ""
                        Try
                            strType = strControlToken.Substring(0, strControlToken.IndexOf(":"))
                        Catch
                        End Try

                        Dim strProperty As String = ""
                        Try
                            strProperty = strControlToken.Substring(strControlToken.IndexOf(":") + 1)
                        Catch
                        End Try


                        If strType.ToUpper = "PROFILE" Then

                            Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                            If Not prop Is Nothing Then

                                AddPropertyControl(prop, plhControls, prop.Visible, objUser, PageNeedsToPostback)

                            End If

                        ElseIf strType.ToUpper = "UPDATEBUTTON" Then

                            Dim btn As New Button
                            btn.Text = strProperty
                            btn.ID = plhControls.ID & "_" & Constants.ControlId_UpdateButton
                            btn.CssClass = "dnnPrimaryAction"
                            plhControls.Controls.Add(btn)

                        ElseIf strType.ToUpper = "DELETEBUTTON" Then

                            Dim btn As New Button
                            btn.Text = strProperty
                            btn.ID = plhControls.ID & "_" & Constants.ControlId_DeleteButton
                            btn.CssClass = "dnnSecondaryAction"
                            plhControls.Controls.Add(btn)

                        ElseIf strType.ToUpper = "USER" Then

                            Select Case strProperty.ToUpper

                                Case "USERNAME"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Username
                                    ctl.Enabled = True
                                    If Not objUser Is Nothing Then
                                        ctl.Text = Convert.ToString(objUser.Username)
                                        ctl.Enabled = False
                                    End If
                                    plhControls.Controls.Add(ctl)


                                Case "FIRSTNAME"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Firstname
                                    Try
                                        ctl.Text = Convert.ToString(objUser.FirstName)
                                    Catch
                                    End Try
                                    ctl.Enabled = True
                                    plhControls.Controls.Add(ctl)

                                Case "PASSWORD1"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Password1
                                    ctl.TextMode = InputMode.Password
                                    ctl.Enabled = True

                                    plhControls.Controls.Add(ctl)

                                Case "PASSWORD2"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Password2
                                    ctl.TextMode = InputMode.Password
                                    ctl.Enabled = True
                                    plhControls.Controls.Add(ctl)

                                Case "LASTNAME"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Lastname
                                    Try
                                        ctl.Text = Convert.ToString(objUser.LastName)
                                    Catch
                                    End Try
                                    ctl.Enabled = True
                                    plhControls.Controls.Add(ctl)

                                Case "EMAIL"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Email
                                    Try
                                        ctl.Text = Convert.ToString(objUser.Email)
                                    Catch
                                    End Try
                                    ctl.Enabled = True

                                    plhControls.Controls.Add(ctl)

                                Case "DISPLAYNAME"

                                    Dim ctl As New TextBox
                                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_Displayname
                                    Try
                                        ctl.Text = Convert.ToString(objUser.DisplayName)
                                    Catch
                                    End Try
                                    ctl.Enabled = True
                                    plhControls.Controls.Add(ctl)

                            End Select

                        End If



                    ElseIf strToken.StartsWith("ERROR:") Then

                        Dim strProperty As String = strToken.Substring(6, strToken.Length - 6)
                        Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                        If Not prop Is Nothing Then
                            Dim pnlError As New Panel
                            pnlError.ID = plhControls.ID & "_" & Constants.ControlId_PanelError & prop.PropertyDefinitionId.ToString
                            pnlError.CssClass = Constants.CssClass_ErrorPanel
                            pnlError.Visible = False
                            pnlError.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/error.png"">"))
                            plhControls.Controls.Add(pnlError)
                        Else
                            Dim pnlError As New Panel
                            pnlError.ID = plhControls.ID & "_" & Constants.ControlId_PanelError & strProperty
                            pnlError.CssClass = Constants.CssClass_ErrorPanel
                            pnlError.Visible = False
                            pnlError.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/error.png"">"))
                            plhControls.Controls.Add(pnlError)
                        End If

                    ElseIf strToken.StartsWith("VALIDATE:") Then

                        Dim strTarget As String = strToken.Split(Char.Parse(":"))(1)
                        Dim strProperty As String = strToken.Split(Char.Parse(":"))(2)

                        If strTarget.ToUpper = "USER" Then

                        End If

                    ElseIf strToken.StartsWith("REQUIRED:") Then

                        Dim strTarget As String = strToken.Split(Char.Parse(":"))(1)
                        Dim strProperty As String = strToken.Split(Char.Parse(":"))(2)

                        If strTarget.ToUpper = "PROFILE" Then

                            Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, strProperty)
                            If Not prop Is Nothing Then
                                If prop.Required Then

                                    Dim pnlRequired As New Panel
                                    pnlRequired.ID = plhControls.ID & "_" & Constants.ControlId_PanelRequired & prop.PropertyDefinitionId.ToString
                                    pnlRequired.CssClass = Constants.CssClass_RequiredPanel
                                    pnlRequired.Visible = True
                                    pnlRequired.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/required.png"" class=""imgIndicator"">"))
                                    plhControls.Controls.Add(pnlRequired)

                                    Dim pnlError As New Panel
                                    pnlError.ID = plhControls.ID & "_" & Constants.ControlId_PanelError & prop.PropertyDefinitionId.ToString
                                    pnlError.CssClass = Constants.CssClass_ErrorPanel
                                    pnlError.Visible = False
                                    pnlError.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/error.png"" class=""imgIndicator"">"))
                                    plhControls.Controls.Add(pnlError)

                                End If
                            End If

                        ElseIf strTarget.ToUpper = "USER" Then

                            Dim blnNeededIndicator As Boolean = True

                            If strProperty.ToLower = "username" AndAlso (objUser Is Nothing = False) Then
                                blnNeededIndicator = False
                            End If

                            If blnNeededIndicator Then

                                Dim pnlRequired As New Panel
                                pnlRequired.ID = plhControls.ID & "_" & Constants.ControlId_PanelRequired & strProperty
                                pnlRequired.CssClass = Constants.CssClass_RequiredPanel
                                pnlRequired.Visible = True
                                pnlRequired.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/required.png"" class=""imgIndicator"">"))
                                plhControls.Controls.Add(pnlRequired)

                                Dim pnlError As New Panel
                                pnlError.ID = plhControls.ID & "_" & Constants.ControlId_PanelError & strProperty
                                pnlError.CssClass = Constants.CssClass_ErrorPanel
                                pnlError.Visible = False
                                pnlError.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/error.png"" class=""imgIndicator"">"))
                                plhControls.Controls.Add(pnlError)

                                If strProperty.ToLower = "username" OrElse strProperty.ToLower = "password1" OrElse strProperty.ToLower = "password2" OrElse strProperty.ToLower = "email" Then

                                    Dim pnlSuccess As New Panel
                                    pnlSuccess.ID = plhControls.ID & "_" & Constants.ControlId_PanelSuccess & strProperty
                                    pnlSuccess.CssClass = Constants.CssClass_SuccessPanel
                                    pnlSuccess.Visible = False
                                    pnlSuccess.Controls.Add(New LiteralControl("<img src=""" & Me.TemplateSourceDirectory & "/images/accept.png"" class=""imgIndicator"">"))
                                    plhControls.Controls.Add(pnlSuccess)

                                End If

                            End If

                        End If


                    End If


                End If

            Next

        End Sub

        Protected Sub AddPropertyValue(ByRef plhControls As ControlCollection, ByVal ProfileProperty As ProfilePropertyDefinition, ByVal objItem As UserInfo)

            Dim strType As String = GetPropertyType(ProfileProperty.DataType)

            Select Case strType.ToLower

                Case "list"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "country"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "date"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToDateTime(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)).ToShortDateString
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)


                Case "datetime"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToDateTime(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)).ToLongDateString
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "integer"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "region"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "locale"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "file"

                    If Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)) <> "" Then
                        'add view control
                        Dim objLiteral As New Literal
                        objLiteral.Text = "<a href=""" & PortalSettings.HomeDirectory & Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)) & ">Herunterladen</a>"
                        objLiteral.EnableViewState = False
                        plhControls.Add(objLiteral)
                    End If


                Case "image"

                    If Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)) <> "" Then
                        'add view control
                        Dim objLiteral As New Literal
                        objLiteral.Text = "<img src=""" & PortalSettings.HomeDirectory & Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)) & """ alt=""" & LocalizeProperty(ProfileProperty) & """ />"
                        objLiteral.EnableViewState = False
                        plhControls.Add(objLiteral)
                    End If


                Case "richtext"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "timezone"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case "truefalse"

                    'add view control
                    Dim objLiteral As New Literal
                    If Convert.ToBoolean(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName)) Then
                        objLiteral.Text = "Ja"
                    Else
                        objLiteral.Text = "Nein"
                    End If

                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)

                Case Else

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem.Profile.GetPropertyValue(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Add(objLiteral)


            End Select


        End Sub

        Protected Sub AddPropertyValue(ByRef plhControls As PlaceHolder, ByVal ProfileProperty As ProfilePropertyDefinition, ByVal objItem As DataRowView)

            Dim strType As String = GetPropertyType(ProfileProperty.DataType)

            Select Case strType.ToLower

                Case "list"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = objItem(ProfileProperty.PropertyName)
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "country"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = objItem(ProfileProperty.PropertyName)
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "date"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToDateTime(objItem(ProfileProperty.PropertyName)).ToShortDateString
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)


                Case "datetime"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToDateTime(objItem(ProfileProperty.PropertyName)).ToLongDateString
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "integer"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "region"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "locale"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "file"

                    If Convert.ToString(objItem(ProfileProperty.PropertyName)) <> "" Then
                        'add view control
                        Dim objLiteral As New Literal
                        objLiteral.Text = "<a href=""" & PortalSettings.HomeDirectory & Convert.ToString(objItem(ProfileProperty.PropertyName)) & ">Herunterladen</a>"
                        objLiteral.EnableViewState = False
                        plhControls.Controls.Add(objLiteral)
                    End If


                Case "image"

                    If Convert.ToString(objItem(ProfileProperty.PropertyName)) <> "" Then
                        'add view control
                        Dim objLiteral As New Literal
                        objLiteral.Text = "<img src=""" & PortalSettings.HomeDirectory & Convert.ToString(objItem(ProfileProperty.PropertyName)) & """ alt=""" & LocalizeProperty(ProfileProperty) & """ />"
                        objLiteral.EnableViewState = False
                        plhControls.Controls.Add(objLiteral)
                    End If


                Case "richtext"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "timezone"

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case "truefalse"

                    'add view control
                    Dim objLiteral As New Literal
                    If Convert.ToBoolean(objItem(ProfileProperty.PropertyName)) Then
                        objLiteral.Text = "Ja"
                    Else
                        objLiteral.Text = "Nein"
                    End If

                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)

                Case Else

                    'add view control
                    Dim objLiteral As New Literal
                    objLiteral.Text = Convert.ToString(objItem(ProfileProperty.PropertyName))
                    objLiteral.EnableViewState = False
                    plhControls.Controls.Add(objLiteral)


            End Select


        End Sub

        Protected Sub AddPropertyControl(ByVal ProfileAttribute As ProfilePropertyDefinition, ByRef plhControls As PlaceHolder, ByVal IsEnabled As Boolean, ByVal objUser As UserInfo, ByRef PageNeedsToPostback As Boolean)

            Dim strType As String = GetPropertyType(ProfileAttribute.DataType)

            Select Case strType.ToLower
                Case "list"

                    Dim drp As New DropDownList
                    drp.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    drp.Attributes.Add("ParentId", plhControls.ID)
                    Dim lc As New Lists.ListController
                    drp.DataSource = lc.GetListEntryInfoItems(ProfileAttribute.PropertyName)
                    drp.DataBind()

                    Try
                        drp.SelectedValue = objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName)
                    Catch
                    End Try

                    drp.Enabled = IsEnabled
                    'drp.EnableAjaxSkinRendering = True
                    plhControls.Controls.Add(drp)

                Case "country"

                    Dim ctl As New DropDownList
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.Attributes.Add("ParentId", plhControls.ID)

                    Dim lc As New Lists.ListController
                    Dim entries As System.Collections.Generic.IEnumerable(Of Lists.ListEntryInfo) = lc.GetListEntryInfoItems("Country")
                    For Each ListEntryInfo In entries
                        ctl.Items.Add(New ListItem(ListEntryInfo.Text, ListEntryInfo.Value))
                    Next
                    Try
                        ctl.Items.FindByText(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName)).Selected = True
                    Catch
                        ctl.Items(0).Selected = True
                    End Try

                    ctl.Enabled = IsEnabled
                    ctl.AutoPostBack = True

                    AddHandler ctl.SelectedIndexChanged, AddressOf drpCountry_SelectedIndexChanged

                    plhControls.Controls.Add(ctl)

                Case "region"

                    Dim ctlDrop As New DropDownList
                    ctlDrop.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_DropdownSuffix & ProfileAttribute.PropertyDefinitionId.ToString
                    ctlDrop.Attributes.Add("ParentId", plhControls.ID)
                    'ctlDrop.EnableAjaxSkinRendering = True
                    ctlDrop.Enabled = IsEnabled
                    ctlDrop.Visible = False

                    Dim ctlText As New TextBox
                    ctlText.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_TextSuffix & ProfileAttribute.PropertyDefinitionId.ToString
                    ctlText.Enabled = IsEnabled
                    ctlText.Attributes.Add("ParentId", plhControls.ID)
                    ctlText.Visible = False

                    Dim drpCountry As DropDownList = Nothing
                    Dim strCountry As String = ""
                    Dim propCountry As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, "Country")
                    If Not propCountry Is Nothing Then

                        Dim obj As Control = FindControlRecursive(plhControls, plhControls.ID & "_" & Constants.ControlId_ProfileProperty & propCountry.PropertyDefinitionId.ToString)
                        If Not obj Is Nothing Then
                            drpCountry = CType(obj, DropDownList)
                            If Not drpCountry Is Nothing Then
                                strCountry = drpCountry.SelectedItem.Text
                            End If
                        End If

                    End If

                    Dim country As Lists.ListEntryInfo = Nothing

                    Dim lc As New Lists.ListController

                    Dim entries As System.Collections.Generic.IEnumerable(Of Lists.ListEntryInfo) = Nothing
                    Dim countries As System.Collections.Generic.IEnumerable(Of Lists.ListEntryInfo) = lc.GetListEntryInfoItems("Country")

                    For Each checkCountry As Lists.ListEntryInfo In countries
                        If checkCountry.Text = strCountry Then
                            country = checkCountry
                            Exit For
                        End If
                    Next

                    If Not country Is Nothing Then
                        entries = lc.GetListEntryInfoItems("Region", "Country." & country.Value)
                    End If

                    Dim blnHasEntries As Boolean = False
                    If Not entries Is Nothing Then
                        If entries.Count > 0 Then
                            blnHasEntries = True
                        End If
                    End If

                    If blnHasEntries Then

                        For Each entry As Lists.ListEntryInfo In entries
                            ctlDrop.Items.Add(New ListItem(entry.Text, entry.Value))
                        Next
                        Try
                            ctlDrop.Items.FindByText(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName)).Selected = True
                        Catch
                        End Try
                        ctlDrop.Visible = True
                        ctlText.Visible = False
                    Else

                        Try
                            ctlText.Text = Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                        Catch
                        End Try
                        ctlText.Visible = True
                        ctlDrop.Visible = False
                    End If

                    plhControls.Controls.Add(ctlDrop)
                    plhControls.Controls.Add(ctlText)

                Case "date"

                    Dim ctl As New RadDatePicker
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.MinDate = New Date(1900, 1, 1)
                    ctl.MaxDate = New Date(2100, 12, 31)

                    Try
                        ctl.SelectedDate = Convert.ToDateTime(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled
                    ctl.EnableAjaxSkinRendering = True
                    plhControls.Controls.Add(ctl)

                Case "datetime"

                    Dim ctl As New RadDateTimePicker
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.MinDate = New Date(1900, 1, 1)
                    ctl.MaxDate = New Date(2100, 12, 31)
                    Try
                        ctl.SelectedDate = Convert.ToDateTime(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled
                    ctl.EnableAjaxSkinRendering = True

                    plhControls.Controls.Add(ctl)

                Case "integer"

                    Dim ctl As New RadNumericTextBox
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    Try
                        ctl.Value = Convert.ToDouble(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled
                    ctl.EnableAjaxSkinRendering = True
                    ctl.MaxLength = ProfileAttribute.Length
                    plhControls.Controls.Add(ctl)


                Case "locale"

                    Dim ctl As New DropDownList

                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.Page = Me.Page
                    ctl.Enabled = IsEnabled

                    ctl.DataValueField = "Name"
                    ctl.DataTextField = "NativeName"

                    ctl.DataSource = LocaleController.Instance.GetCultures(LocaleController.Instance.GetLocales(PortalId))
                    ctl.DataBind()

                    Try
                        If Not String.IsNullOrEmpty(Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))) Then
                            ctl.SelectedValue = Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                        End If
                    Catch
                    End Try

                    plhControls.Controls.Add(ctl)

                Case "image"

                    PageNeedsToPostback = True

                    Dim ctl As New DotNetNuke.Web.UI.WebControls.DnnImageEditControl
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.User = objUser
                    If IsEnabled Then
                        ctl.EditMode = UI.WebControls.PropertyEditorMode.Edit
                    Else
                        ctl.EditMode = UI.WebControls.PropertyEditorMode.View
                    End If

                    Try
                        ctl.Value = objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName)
                    Catch
                    End Try

                    ctl.DataBind()

                    plhControls.Controls.Add(ctl)

                Case "file"

                    PageNeedsToPostback = True
                    Dim ctl As New DotNetNuke.Web.UI.WebControls.DnnFileEditControl
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    ctl.User = objUser
                    If IsEnabled Then
                        ctl.EditMode = UI.WebControls.PropertyEditorMode.Edit
                    Else
                        ctl.EditMode = UI.WebControls.PropertyEditorMode.View
                    End If

                    Try
                        ctl.Value = objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName)
                    Catch
                    End Try

                    plhControls.Controls.Add(ctl)

                Case "richtext"

                    Dim ctl As New TextBox
                    ctl.TextMode = InputMode.MultiLine
                    ctl.Rows = 8
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    Try
                        ctl.Text = Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled
                    ctl.MaxLength = ProfileAttribute.Length
                    plhControls.Controls.Add(ctl)

                Case "timezone", "timezoneinfo"

                    Dim ctl As New DnnTimeZoneComboBox
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    Try
                        If Not String.IsNullOrEmpty(Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))) Then
                            ctl.SelectedValue = Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                        End If
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled

                    plhControls.Controls.Add(ctl)

                Case "truefalse", "checkbox"

                    Dim ctl As New CheckBox
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    Try
                        ctl.Checked = Convert.ToBoolean(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try

                    plhControls.Controls.Add(ctl)

                Case Else

                    Dim ctl As New TextBox
                    ctl.ID = plhControls.ID & "_" & Constants.ControlId_ProfileProperty & ProfileAttribute.PropertyDefinitionId.ToString
                    Try
                        ctl.Text = Convert.ToString(objUser.Profile.GetPropertyValue(ProfileAttribute.PropertyName))
                    Catch
                    End Try
                    ctl.Enabled = IsEnabled
                    ctl.MaxLength = ProfileAttribute.Length

                    plhControls.Controls.Add(ctl)

            End Select

        End Sub

        Public Sub UpdateProfileProperties(ByRef Container As Control, ByRef oUser As UserInfo, Properties As List(Of String))
            Dim strUpdated As String = ""
            UpdateProfileProperties(Container, oUser, strUpdated, Properties)
        End Sub

        Public Sub UpdateProfileProperties(ByRef Container As Control, ByRef oUser As UserInfo, ByRef strUpdated As String, Properties As List(Of String))

            Dim oldAccount As UserInfo = oUser

            'loop trough dynamic profile attributes and set those
            For Each itemProp As String In Properties
                Try
                    Dim prop As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalId, itemProp.Substring(2))
                    If Not prop Is Nothing Then

                        Dim ctl As Control = GetPropertyControl(prop, Container)
                        If Not ctl Is Nothing Then
                            If TypeOf (ctl) Is DropDownList Then

                                Dim value As String = CType(ctl, DropDownList).SelectedValue.Trim


                                If prop.PropertyName.ToLower = "region" Then
                                    value = CType(ctl, DropDownList).SelectedItem.Text.Trim
                                End If
                                If prop.PropertyName.ToLower = "country" Then
                                    value = CType(ctl, DropDownList).SelectedItem.Text.Trim
                                End If

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadDateTimePicker Then

                                Dim value As String = CType(ctl, Telerik.Web.UI.RadDateTimePicker).DbSelectedDate.ToString

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadTimePicker Then

                                Dim value As String = CType(ctl, Telerik.Web.UI.RadTimePicker).DbSelectedDate.ToString.Trim

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadDatePicker Then

                                Dim value As String = CType(ctl, Telerik.Web.UI.RadDatePicker).DateInput.DbSelectedDate.ToString.Trim

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is CheckBox Then

                                Dim value As String = CType(ctl, CheckBox).Checked.ToString

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)


                            ElseIf TypeOf (ctl) Is TextBox Then

                                Dim value As String = CType(ctl, TextBox).Text.Trim

                                Dim oldValue As String = oldAccount.Profile.GetPropertyValue(prop.PropertyName)
                                If oldValue <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is Telerik.Web.UI.RadNumericTextBox Then

                                Dim value As String = CType(ctl, Telerik.Web.UI.RadNumericTextBox).Value.ToString

                                If oldAccount.Profile.GetPropertyValue(prop.PropertyName) <> value Then
                                    Dim strProperty As String = prop.PropertyName
                                    If Localization.GetString("ProfileProperties_" & prop.PropertyName, ProfileResourcefile) <> "" Then
                                        strProperty = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
                                    End If
                                    strUpdated += strProperty & ", "
                                End If

                                oUser.Profile.SetProfileProperty(prop.PropertyName, value)

                            ElseIf TypeOf (ctl) Is DotNetNuke.Web.UI.WebControls.DnnTimeZoneComboBox Then
                                oUser.Profile.SetProfileProperty(prop.PropertyName, CType(ctl, DotNetNuke.Web.UI.WebControls.DnnTimeZoneComboBox).SelectedValue)

                            ElseIf TypeOf (ctl) Is DotNetNuke.Web.UI.WebControls.DnnImageEditControl Then
                                oUser.Profile.SetProfileProperty(prop.PropertyName, CType(ctl, DotNetNuke.Web.UI.WebControls.DnnImageEditControl).Value)

                            ElseIf TypeOf (ctl) Is DotNetNuke.Web.UI.WebControls.DnnFileEditControl Then
                                oUser.Profile.SetProfileProperty(prop.PropertyName, CType(ctl, DotNetNuke.Web.UI.WebControls.DnnFileEditControl).Value)

                            End If
                        End If

                    End If
                Catch
                End Try
            Next

        End Sub

        Public Sub ManageRegionLabel(ByRef Container As Control)

            'we need to check for double labels in region control, if that is on the page

            Dim ctlRegionDrop As Control = Nothing
            Dim ctlRegionText As Control = Nothing

            Dim propRegion As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, "Region")
            If Not propRegion Is Nothing Then
                ctlRegionDrop = FindControlRecursive(Me.Page, Container.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_DropdownSuffix & propRegion.PropertyDefinitionId.ToString)
                ctlRegionText = FindControlRecursive(Me.Page, Container.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_TextSuffix & propRegion.PropertyDefinitionId.ToString)
            End If

            Dim objControlForDropdown As Control = Nothing
            Dim objLabelForDropdown As Label = Nothing
            Dim lblDropdownId As String = Container.ID & "_RESX_PROFILE" & Constants.ControlId_DropdownSuffix & "_" & propRegion.PropertyName
            objControlForDropdown = FindControlRecursive(Container, lblDropdownId)
            If Not objControlForDropdown Is Nothing Then
                If TypeOf objControlForDropdown Is Label Then
                    objLabelForDropdown = CType(objControlForDropdown, Label)
                End If
            End If

            Dim objControlForTextbox As Control = Nothing
            Dim objLabelForTextbox As Label = Nothing
            Dim lblTextboxId As String = Container.ID & "_RESX_PROFILE" & Constants.ControlId_TextSuffix & "_" & propRegion.PropertyName
            objControlForTextbox = FindControlRecursive(Container, lblTextboxId)
            If Not objControlForTextbox Is Nothing Then
                If TypeOf objControlForTextbox Is Label Then
                    objLabelForTextbox = CType(objControlForTextbox, Label)
                End If
            End If

            If Not ctlRegionDrop Is Nothing Then
                If ctlRegionDrop.Visible = True Then
                    If Not objLabelForDropdown Is Nothing Then objLabelForDropdown.Visible = True
                    If Not objLabelForTextbox Is Nothing Then objLabelForTextbox.Visible = False
                Else
                    If Not objLabelForDropdown Is Nothing Then objLabelForDropdown.Visible = False
                    If Not objLabelForTextbox Is Nothing Then objLabelForTextbox.Visible = True
                End If
            End If

            If Not ctlRegionText Is Nothing Then
                If ctlRegionText.Visible = True Then
                    If Not objLabelForDropdown Is Nothing Then objLabelForDropdown.Visible = False
                    If Not objLabelForTextbox Is Nothing Then objLabelForTextbox.Visible = True
                Else
                    If Not objLabelForDropdown Is Nothing Then objLabelForDropdown.Visible = True
                    If Not objLabelForTextbox Is Nothing Then objLabelForTextbox.Visible = False
                End If
            End If

        End Sub

        Public Sub RebindUserImage()

        End Sub

        Protected Sub drpCountry_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)


            Dim drpCountry As DropDownList = CType(o, DropDownList)
            Dim objParent As String = drpCountry.Attributes("ParentId")

            Dim strCountry As String = drpCountry.Text

            Dim country As Lists.ListEntryInfo = Nothing

            Dim lc As New Lists.ListController

            Dim entries As System.Collections.Generic.IEnumerable(Of Lists.ListEntryInfo) = Nothing
            Dim countries As System.Collections.Generic.IEnumerable(Of Lists.ListEntryInfo) = lc.GetListEntryInfoItems("Country")

            For Each checkCountry As Lists.ListEntryInfo In countries
                If checkCountry.Text = strCountry Then
                    country = checkCountry
                    Exit For
                End If
            Next

            If Not country Is Nothing Then
                entries = lc.GetListEntryInfoItems("Region", "Country." & country.Value)
            End If

            Dim blnHasEntries As Boolean = False
            If Not entries Is Nothing Then
                If entries.Count > 0 Then
                    blnHasEntries = True
                End If
            End If

            Dim ctlRegionDrop As Control = Nothing
            Dim ctlRegionText As Control = Nothing

            Dim propRegion As ProfilePropertyDefinition = ProfileController.GetPropertyDefinitionByName(PortalSettings.PortalId, "Region")
            If Not propRegion Is Nothing Then

                ctlRegionDrop = FindControlRecursive(Me.Page, objParent & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_DropdownSuffix & propRegion.PropertyDefinitionId.ToString)
                ctlRegionText = FindControlRecursive(Me.Page, objParent & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_TextSuffix & propRegion.PropertyDefinitionId.ToString)

            End If

            If blnHasEntries Then
                If Not ctlRegionDrop Is Nothing Then
                    ctlRegionDrop.Visible = True
                    CType(ctlRegionDrop, DropDownList).Items.Clear()
                    For Each entry As Lists.ListEntryInfo In entries
                        CType(ctlRegionDrop, DropDownList).Items.Add(New ListItem(entry.Text, entry.Value))
                    Next
                End If
                If Not ctlRegionText Is Nothing Then
                    ctlRegionText.Visible = False
                End If
            Else
                If Not ctlRegionDrop Is Nothing Then
                    ctlRegionDrop.Visible = False
                End If
                If Not ctlRegionText Is Nothing Then
                    ctlRegionText.Visible = True
                End If
            End If


        End Sub

        Protected Function GetPropertyControl(ByVal ProfProperty As ProfilePropertyDefinition, ByRef objControl As Control) As Control

            Dim strType As String = GetPropertyType(ProfProperty.DataType)
            Select Case strType.ToLower

                Case "region"

                    Dim ctlDrop As DropDownList = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_DropdownSuffix & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctlDrop Is Nothing Then
                        If ctlDrop.Visible Then
                            Return ctlDrop
                        End If
                    End If

                    Dim ctlText As TextBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & Constants.ControlId_TextSuffix & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctlText Is Nothing Then
                        Return ctlText
                    End If

                Case "list", "country", "locale"

                    Dim ctl As DropDownList = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "timezoneinfo"

                    Dim ctl As DnnTimeZoneComboBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "integer"

                    Dim ctl As Telerik.Web.UI.RadNumericTextBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "richtext"

                    Dim ctl As TextBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "truefalse"

                    Dim ctl As CheckBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "date"

                    Dim ctl As Telerik.Web.UI.RadDatePicker = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "datetime"

                    Dim ctl As Telerik.Web.UI.RadDateTimePicker = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "image"

                    Dim ctl As DotNetNuke.Web.UI.WebControls.DnnImageEditControl = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case "file"

                    Dim ctl As DotNetNuke.Web.UI.WebControls.DnnFileEditControl = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

                Case Else

                    Dim ctl As TextBox = objControl.FindControl(objControl.ID & "_" & Constants.ControlId_ProfileProperty & ProfProperty.PropertyDefinitionId.ToString)
                    If Not ctl Is Nothing Then
                        Return ctl
                    End If

            End Select

            Return Nothing

        End Function

        Protected Sub AddSuccessIndicator(ByVal Attribute As String, ByRef objControl As Control)


            Dim pnlRequired As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelRequired & Attribute), Panel)
            If Not pnlRequired Is Nothing Then
                pnlRequired.Visible = False
            End If

            Dim pnlError As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelError & Attribute), Panel)
            If Not pnlError Is Nothing Then
                pnlError.Visible = False
            End If

            Dim pnlSucess As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelSuccess & Attribute), Panel)
            If Not pnlSucess Is Nothing Then
                pnlSucess.Visible = True
            End If


        End Sub

        Protected Sub AddErrorIndicator(ByVal Attribute As String, ByRef objControl As Control)


            Dim pnlRequired As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelRequired & Attribute), Panel)
            If Not pnlRequired Is Nothing Then
                pnlRequired.Visible = False
            End If

            Dim pnlError As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelError & Attribute), Panel)
            If Not pnlError Is Nothing Then
                pnlError.Visible = True
            End If

            Dim pnlSucess As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelSuccess & Attribute), Panel)
            If Not pnlSucess Is Nothing Then
                pnlSucess.Visible = False
            End If

        End Sub

        Protected Sub RemoveErrorIndicator(ByVal Attribute As String, ByRef objControl As Control, ByVal IsRequired As Boolean)

            Dim pnlRequired As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelRequired & Attribute), Panel)
            If Not pnlRequired Is Nothing Then
                pnlRequired.Visible = IsRequired
            End If

            Dim pnlError As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelError & Attribute), Panel)
            If Not pnlError Is Nothing Then
                pnlError.Visible = False
            End If

            Dim pnlSucess As Panel = CType(FindControlRecursive(objControl, objControl.ID & "_" & Constants.ControlId_PanelSuccess & Attribute), Panel)
            If Not pnlSucess Is Nothing Then
                pnlSucess.Visible = False
            End If

        End Sub

        Protected Function GetPropertiesFromTempate(ByVal Template As String) As List(Of String)

            Dim lstProperties As New List(Of String)

            Dim delimStr As String = "[]"
            Dim delimiter As Char() = delimStr.ToCharArray()

            Dim templateArray As String()
            templateArray = Template.Split(delimiter)

            For iPtr As Integer = 0 To templateArray.Length - 1 Step 2


                If iPtr < templateArray.Length - 1 Then

                    Dim strToken As String = templateArray(iPtr + 1)

                    If strToken.StartsWith("CTL:") Then

                        Dim strControlToken As String = ""
                        Try
                            strControlToken = strToken.Substring(4, strToken.Length - 4)
                        Catch
                        End Try

                        Dim strType As String = ""
                        Try
                            strType = strControlToken.Substring(0, strControlToken.IndexOf(":"))
                        Catch
                        End Try

                        Dim strProperty As String = ""
                        Try
                            strProperty = strControlToken.Substring(strControlToken.IndexOf(":") + 1)
                        Catch
                        End Try

                        If strType.ToUpper = "PROFILE" Then

                            lstProperties.Add("P:" & strProperty)

                        ElseIf strType.ToUpper = "USER" Then

                            lstProperties.Add("U:" & strProperty)

                        End If

                    End If

                End If

            Next

            Return lstProperties

        End Function

        Public Function GetTempFolderPath(ByVal PropertyName As String) As String

            Dim strPath As String = ResolveUrl("~/App_Data/dnnWerk.Users/")
            If Not System.IO.Directory.Exists(Server.MapPath(strPath)) Then
                System.IO.Directory.CreateDirectory(Server.MapPath(strPath))
            End If

            strPath = ResolveUrl("~/App_Data/dnnWerk.Users/" & PropertyName)
            If Not System.IO.Directory.Exists(Server.MapPath(strPath)) Then
                System.IO.Directory.CreateDirectory(Server.MapPath(strPath))
            End If

            Return strPath & "/"

        End Function


#End Region

#Region "Localization Utilities"

        Protected Function LocalizeProperty(ByVal prop As ProfilePropertyDefinition) As String
            Dim strText As String = prop.PropertyName
            Try
                strText = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Text", ProfileResourcefile)
            Catch
            End Try
            Return strText
        End Function

        Protected Function LocalizePropertyHelp(ByVal prop As ProfilePropertyDefinition) As String
            Dim strText As String = prop.PropertyName
            Try
                strText = Localization.GetString("ProfileProperties_" & prop.PropertyName & ".Help", ProfileResourcefile)
            Catch
            End Try
            Return strText
        End Function

        Protected Function LocalizePropertyCategory(ByVal prop As ProfilePropertyDefinition) As String
            Dim strText As String = prop.PropertyCategory
            Try
                strText = Localization.GetString("ProfileProperties_" & prop.PropertyCategory & ".Header", ProfileResourcefile)
            Catch
            End Try
            Return strText
        End Function

#End Region

#Region "Template Utilities"

        Private Function GetTemplatePath(ByVal ViewMode As String, ByVal Templatename As String) As String

            Dim path As String = Server.MapPath(Me.ModuleDirectory & "/templates/" & ViewMode & "/" & Templatename & ".txt")

            If System.IO.File.Exists(path) Then
                Return path
            End If

            Return ""

        End Function

#End Region

    End Class
End Namespace


